package com.lr.falsework.common.tool;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class FileTool {

	
	public static void copy(File source,File target){
		FileInputStream input = null;
		FileOutputStream output = null;
		try {
			input = new FileInputStream(source);
			output = new FileOutputStream(target);
			byte[] bt = new byte[1024];
			int realbyte = 0;
			int count=0;
			while ((realbyte = input.read(bt)) > 0) {
				count++;
				output.write(bt,0,realbyte);
				if(count>100){
					output.flush();
					count=0;
				}
			}
			
			output.close();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if (input != null) {
					input.close();
				}
				if (output != null) {
					output.close();
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
	
	public static String getSuffix(File file){
		String path=file.getPath();
	return 	path.substring(path.lastIndexOf("."));
	}
	
	public static void main(String[] args) {
		File source=new File("D:\\Price Changes.xls");
//		copy(source, new File(source.getParent()+"\\"+UUID.randomUUID().toString().replace("-", "")+".xls"));
		System.out.println(getSuffix(source));
		
	}
}
